// pages/distribut/after_sales/after_sales.js
var app = getApp();
var request = app.request;
var setting = app.globalData.setting;
var common = require('../../../utils/common.js');
var util = require('../../../utils/util.js');

Page({

	/**
	 * 页面的初始数据
	 */
	data: {
		url: setting.url,
		num: 1,
		index: 0,

		yuanyin: '',
		textlist: ['买贵了', '买错了买多了', '优惠未享受', '临时有事无法提货', '下错门店'],
		opinion: [],
		rec_id: '',
		info:{}
	},
	// 上传凭证
	changeStoreImg: function() {
		var that = this;
		wx.chooseImage({
			count: 1, //最多1张图片,默认9
			sizeType: ['compressed', 'original'], // 可以指定是原图还是压缩图，默认二者都有
			sourceType: ['camera', 'album'], // 可以指定来源是相册还是相机，默认二者都有
			success: function(res) {
				request.uploadFile('/api/distribut/upload_store_img', {
					filePath: res.tempFilePaths[0],
					name: 'store_img',
					success: function(res) {
						let data = [...that.data.opinion]
						data.push(res.data.result)
						that.setData({
							opinion: data
						});
					}
				});
			}
		});
	},
	bindPickerChange: function(e) {
		console.log(e)
		this.setData({
			index: e.detail.value,
			yuanyin: this.data.info.return_reason[e.detail.value]
		})
	},
	// 数量加减
	addNum() {
		this.setData({
			num: this.data.num + 1
		})
	},
	subNum() {
		if (1 >= this.data.num) {
			return
		} else {
			this.setData({
				num: this.data.num - 1
			})
		}
	},
	/**
	 * 生命周期函数--监听页面加载
	 */
	onLoad(options) {
		this.setData({
			rec_id: options.rec_id,
		});
		this.getinfo()
	},
	// 提交申请退款
	submit(){
		let data={
			rec_id:this.data.rec_id,
			return_images:this.data.opinion,
			reason:this.data.yuanyin
		}
		let that = this
		
		request.post('/api/shop/returnGood', {
			data:data,
			success: function(res) {
				if (res.data.status == 1) {
					wx.showToast({
						title: '退款申请成功'
					})
					setTimeout(()=>{
						wx.navigateBack({ //返回上一页  
							delta: 1
						})
					},2000)
				}
			}
		});
	},
	// 拨打电话
	tels(e) {
		console.log(e)
		wx.makePhoneCall({
			phoneNumber: e.currentTarget.dataset.id,
		})
	},
	// 获取订单详情
	getinfo() {
		let that = this
		request.get('/api/shop/returnGood', {
			data:{rec_id:that.data.rec_id},
			success: function(res) {
				console.log(res)
				if (res.data.status == 1 && res.data.result) {
					that.setData({
						info: res.data.result
					});
				}else{
					wx.navigateBack({
					    delta: 1
					  });
				}
			}
		});
	},
	/**
	 * 生命周期函数--监听页面初次渲染完成
	 */
	onReady() {

	},

	/**
	 * 生命周期函数--监听页面显示
	 */
	onShow() {

	},

	/**
	 * 生命周期函数--监听页面隐藏
	 */
	onHide() {

	},

	/**
	 * 生命周期函数--监听页面卸载
	 */
	onUnload() {

	},

	/**
	 * 页面相关事件处理函数--监听用户下拉动作
	 */
	onPullDownRefresh() {

	},

	/**
	 * 页面上拉触底事件的处理函数
	 */
	onReachBottom() {

	},

	/**
	 * 用户点击右上角分享
	 */
	onShareAppMessage() {

	}
})